package com.ui.handle;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class Job {

	// 任务是否完成
	private boolean finish = false;
	// 任务参数
	private Map<String, Object> parmMap = new HashMap<String, Object>();

	/**
	 * @Description 任务已完成
	 * @param 参数
	 * @return void 返回类型
	 * @throws
	 */
	public void finished() {
		this.finish = true;
	}

	/**
	 * @Description 是否完成
	 * @param @return 参数
	 * @return boolean 返回类型
	 * @throws
	 */
	public boolean isFinished() {
		return finish;
	}

	/**
	 * @Description 设置任务的参数
	 * @param @param key
	 * @param @param parameter 参数
	 * @return void 返回类型
	 * @throws
	 */
	public void putParameter(String key, Object parameter) {
		parmMap.put(key, parameter);
	}

	public Map<String, Object> getParmMap() {
		return parmMap;
	}

	public void setParmMap(Map<String, Object> parmMap) {
		this.parmMap = parmMap;
	}

	/**
	 * @Description 取得任务的参数值
	 * @param @param key
	 * @param @return 参数
	 * @return Object 返回类型
	 * @throws
	 */
	public Object getObjectParmt(String key) {
		return parmMap.get(key);
	}

	public String getStringParmt(String key) {
		return parmMap.get(key).toString();
	}

	public Number getIntParmt(String key) {
		Object obj = parmMap.get(key);
		Integer it = Integer.valueOf(obj.toString());
		return it;
	}

	public Number getDoubleParmt(String key) {
		Object obj = parmMap.get(key);
		Double it = Double.valueOf(obj.toString());
		return it;
	}

	public Collection<String> getNameParmt() {
		Set<String> keys = parmMap.keySet();
		return keys;
	}

	/**
	 * @Description 复制数据
	 * @param @return 参数
	 * @return Job 返回类型
	 * @throws
	 */
	public Job copy() {
		Job j = new Job();
		if (isFinished())
			j.finished();
		Map<String, Object> parmMap = new HashMap<String, Object>();
		Map<String, Object> old = getParmMap();
		if (old != null && old.size() > 0) {
			parmMap.putAll(getParmMap());
			j.setParmMap(parmMap);
		}
		return j;
	}

}
